//
//  HFQIndicationView.m
//  AiShangJinFuSalesman
//
//  Created by AiShangTong on 2017/6/15.
//  Copyright © 2018年 AiShangTong. All rights reserved.
//

#import "HFQIndicationView.h"

@implementation HFQIndicationView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.color = ThemeMaoColor;
        self.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
        
    }
    return self;
}

+ (instancetype)sharedView
{
    static HFQIndicationView *indicationView;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        indicationView = [[self alloc] initWithFrame:CGRectMake(0, 0, ScreenWidthMao, ScreenHeight)];
        indicationView.center = CGPointMake(ScreenWidthMao/2, ScreenHeight/2-SafeAreaTopHeight);
    });
    return indicationView;
}


+(void)showInView:(UIView *)view{
    
    [[HFQIndicationView sharedView] startAnimating];
    [view addSubview:[HFQIndicationView sharedView]];
}

+(instancetype)sharedViewWithCenter:(CGPoint)point{
    static HFQIndicationView *indicationView;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        indicationView = [[self alloc] initWithFrame:CGRectMake(0, 0, ScreenWidthMao, ScreenHeight)];
        indicationView.center = point;
    });
    return indicationView;
}
+(void)showInView:(UIView *)view Point:(CGPoint)point{
    
    [[HFQIndicationView sharedViewWithCenter:point] startAnimating];
    [view addSubview:[HFQIndicationView sharedViewWithCenter:point]];
}
+(void)dismissWithCenter:(CGPoint)point{
    [[HFQIndicationView sharedViewWithCenter:point] stopAnimating];
    [[HFQIndicationView sharedViewWithCenter:point] removeFromSuperview];
}
+(void)dismiss{
    
    if ([NSThread isMainThread]) {
        [[HFQIndicationView sharedView] stopAnimating];
        [[HFQIndicationView sharedView] removeFromSuperview];
    }else {
        dispatch_async(dispatch_get_main_queue() , ^{
            
            [[HFQIndicationView sharedView] stopAnimating];
            [[HFQIndicationView sharedView] removeFromSuperview];
        });

    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
